//打开客户报价详情信息
function checkClientDetailPrice($id,$client){
	var bag = $("#bag").html("");
	bag.load("clientDetailPrice",function(response,status,xhr){
		showClientInfos($client);
		var data="id="+$id+"&currentPages=";
		showDetailPriceContent(data,$client);
		$("#clientPriceCostIds").val($id);
	});o
	
}

//显示客户基本信息
function showClientInfos($id){
	var data="id="+$id;
	var url="/trade-wzj-web/ClientContrillerYang/getClientInfoById";
	var clientObject=postMethod(url,data,"POST");
	var v=$("#clientInfos").html("");
	var str="";
	str=str+"<p>客户名称:<span>"+clientObject.clientName+"</span></p>"+
			"<p>地址:<span>"+clientObject.clientAddress+"</span></p>"+
			"<p>TEL:<span>"+clientObject.clientFax+"</span></p>"+
			"<p>手机:<span>"+clientObject.clientPhone+"</span></p>"+
			"<p>联系人:<span>"+clientObject.clientContacts+"</span></p>";
	v.append(str);
}

//显示报价详情信息
function showDetailPriceContent($data,$id){
	var objTable=$("#clientDetailPriceTable tbody").html("");
	var str="";
	var datas=$data;
	var url="/trade-wzj-web/ClientInfoQuotaControllerYang/getClientDetailPriceById";
	//定义总额
	var total=0.0;
	
	var result=postMethod(url,"POST",datas);
	var list=result.list;
	
	if(list.length>0){
		for(var i=0;i<list.length;i++){
		str=str+"<tr>" +
					"<td><div class='checkbox' style='margin-top:0px'>"+
    "<label>"+
      "<input type='checkbox' value='"+list[i].productInfoQuotaID+"'  name='allClientPrice'>"+
    "</label>"+
    "</div></td>"+
    "<td><input type='hidden' value='"+$id+"' id='clientIs'>"+list[i].productName+"</td>"+
    
		"<td><input type='hidden' value='"+list[i].clientQuotaID+"' id='clientQuota'>"+list[i].productNum+"</td>"+
		"<td>"+list[i].quotaPrice+"</td>"+
		"<td>"+list[i].quotaMoney+"</td>"+
		"<td>"+list[i].expirationDate+"</td>"+
		"<td>"+list[i].expirationDate+"</td>"+
		
		"<td>1</td>";
			
		total=total+list[i].quotaMoney;
		}
	}
	objTable.append(str);
	var page=divideClientPricePage(result);
	var p = $("#footPagess").html("");
	p.append(page);
	$("#clientPriceTotal  span").html(total);
}

//全选客户报价产品

function onclickAllClientPrice(){
var list = document.getElementsByName("allClientPrice");
var li = document.getElementsByName("allClientPrices");
	
	if(li[0].checked){
		for(var i=0;i<list.length;i++){
			list[i].checked=true;
		}
	}else{
		for(var i=0;i<list.length;i++){
			list[i].checked=false;
		}
	}
	var str="";
	for(var i=0;i<list.length;i++){
		if(list[i].checked){
			str=str+list[i].value+",";
		}
		
	}
}





//获取页码信息
function divideClientPricePage($clientList){
	var page="";
	var ids=$("#clientQuota").val();
	var con = $("#clientPriceProduct").val();
	page = page+"<div class='row' style='margin:0px'>" +
	"<div class='col-md-3 col-sm-3 col-xs-3' style='padding-top:0.7rem'>"+
		"<span style='font-weight:bold'>总记录数 "+$clientList.total+"   |  总页数 "+$clientList.pages+"</span>"+
	"</div>"+
	"<div class='col-md-offset-7 col-sm-offset-7 col-xs-offset-7'>"
	+"<nav aria-label='Page navigation'>"+
"<ul class='pagination pagination-sm'>";
	if($clientList.prePage>0){
		page = page+"<li><a href='#' onclick='clientPriceDetail("+$clientList.firstPage+",\""+con+"\","+ids+")'>首页</a></li>"+
		"<li><a href='#' onclick='clientPriceDetail("+$clientList.prePage+",\""+con+"\","+ids+")'>上一页</a></li>";
				
	}
	if($clientList.nextPage<=$clientList.lastPage && $clientList.nextPage>0){
		page = page+"<li><a href='#' onclick='clientPriceDetail("+$clientList.nextPage+",\""+con+"\","+ids+")'>下一页</a></li>"+
		"<li><a href='#' onclick='clientPriceDetail("+$clientList.lastPage+",\""+con+"\","+ids+")'>末页</a></li>";
	}
	page = page+"</li>"+
"</ul>"+
"</nav>"+
"</div>"+
"</div>";
	return page;
	
}

//点击页码功能
function clientPriceDetail($num,$obj,$pri){
	//获取参数
	var data="id="+$pri+"&currentPages="+$num+"&productName="+$obj;
	showDetailPriceContent(data);
}

//选择所有信息
function onclickAllCheck(){
	var list = document.getElementsByName("checkProductId");
	var ob = document.getElementsByName("alls");
	if(ob[0].checked==true){
		for(var i=0;i<list.length;i++){
			list[i].checked=true;
		}
	}else{
		for(var i=0;i<list.length;i++){
			list[i].checked=false;
		}
	}
}




//查询客户报价产品表信息
function searchProduct(){
	
}

//修改产品信息如价格、数量
function openUpdateClientProduct($productId){
	//参数
	var data=$productId;
	//路径
	var url="/trade-wzj-web/test/selectClientQuotaDetails";
	var obj = postMethod(url,data,"POST");
	var objList=obj.list;
	var str="";
	var tab = $("#updateClientPriceTable tbody").html("");
	
	tab.append(str);
	//打开修改页面
	$("#updateClientPriceDetailModal").modal("show");
}

//查询客户报价详情商品信息
function searchProducts(){
	var dt=$("#clientPriceCostIds").val();
	var pr=$("#clientIs").val();
	var url="trade-wzj-web/ClientInfoQuotaControllerYang/getClientDetailPriceById";
	var data="id="+dt+"&currentPages="+"&productName="+$("#supProductNames").val();
	showDetailPriceContent(data,pr);
}


//保存修改产品信息
function saveUpdate(){
	var con = $("#updateClientPriceForm").Validform({
		tiptype:1
	});
	var bool=con.check();
	if(!bool){
		$("#saveUpdatePrice").popover("toggle");
		return;
	}
	//获取数据
	var data = $("#updateClientPriceForm").serialize();
	var url="";
	var bol = postMethod(url,data,"POST");
	if(bol){
		alert("修改成功!");
	}else{
		alert("修改失败!");
	}
	var shows="priceProduct="+$("#priceProduct").val()+"&pageNum="+$("#page").val();
	//调用查询方法
	showDetailPriceContent(shows);
	$("#updateClientPriceDetailModal").modal("hide");
}

//全局生成客户订单集合
var clientsOrder="";

//生成客户订单按钮
function saveClientOrders(){
	var cli = $("#clientIs").val;
	var obj=$("#saveClientOrdersTable tbody").html("");
	var url="/trade-wzj-web/ClientInfoQuotaControllerYang/getListClientProduct";
	//获取选中的产品
	var clientId=document.getElementsByName("allClientPrice");
	var cliArray=[];
	for(var i=0;i<clientId.length;i++){
		if(clientId[i].checked==true){
			cliArray.push(clientId[i].value);
		}
	}
	var data="clientInfoId="+$("#clientPriceCostIds").val()+"&productId="+cliArray;
	//调用提交方法
	var result = postMethod(url,data,"POST");
	clientsOrder  = result;
	
	var str="";
	if(clientsOrder.length>0){
		for(var i=0;i<clientsOrder.length;i++){
			str=str+"<tr>" +
			"<td><input datatype='*' nullmsg='信息不完整' name='productID' type='hidden' value='"+clientsOrder[i].productID+"'><input  class='form-control' type='text' value='"+clientsOrder[i].productName+"' style='text-align:center'></td>" +
			"<td><input datatype='*' nullmsg='单位不能为空'  name='Unit' class='form-control' type='text' value='' style='text-align:center'></td>" +
			"<td><input  datatype='*' nullmsg='数量不能为空' name='productNum' class='form-control' type='text' value='"+clientsOrder[i].productNum+"' style='text-align:center'></td>" +
			"<td><input datatype='*' nullmsg='单价不能为空'  name='quotaPrice' class='form-control' type='text' value='"+clientsOrder[i].quotaPrice+"' style='text-align:center'></td>" +
			"<td><input datatype='*' nullmsg='总额不能为空'  name='quotaMoney' class='form-control' type='text' value='"+clientsOrder[i].quotaMoney+"' style='text-align:center'></td>" +
			"<td><a href='#' onclick='removeClientProduct("+clientsOrder[i].productID+")'><span class='glyphicon glyphicon-remove' style='margin-top:0.2rem'></span></a></td>" +
			
		"</tr>";
		}
		
	}
	
	obj.append(str);
	
	
	$("#saveClientOrdersModal").modal("show");
}


//删除生成客户报价信息
function removeClientProduct($id){
	for(var i=0;i<clientsOrder.length;i++){
		if(clientsOrder[i].productID==$id){
			clientsOrder.splice(i,1);
		}
	}
	var obj=$("#saveClientOrdersTable tbody").html("");
	var str="";
	if(clientsOrder.length>0){
		for(var i=0;i<clientsOrder.length;i++){
			str=str+"<tr>" +
						"<td><input name='productID' type='hidden' value='"+clientsOrder[i].productID+"'><input  class='form-control' type='text' value='"+clientsOrder[i].productName+"' style='text-align:center'></td>" +
						"<td><input name='Unit' class='form-control' type='text' value='' style='text-align:center'></td>" +
						"<td><input name='productNum' class='form-control' type='text' value='"+clientsOrder[i].productNum+"' style='text-align:center'></td>" +
						"<td><input name='quotaPrice' class='form-control' type='text' value='"+clientsOrder[i].quotaPrice+"' style='text-align:center'></td>" +
						"<td><input name='quotaMoney' class='form-control' type='text' value='"+clientsOrder[i].quotaMoney+"' style='text-align:center'></td>" +
						"<td><input name='deliveryDate' class='form-control' type='text' value='' style='text-align:center'></td>" +
						"<td><a href='#' onclick='removeClientProduct("+clientsOrder[i].productID+")'><span class='glyphicon glyphicon-remove' style='margin-top:0.2rem'></span></a></td>" +
						
					"</tr>";
		}
		
	}
	
	obj.append(str);
}

//点击确定按钮，生成客户订单
function saveClientOrdersBtn(){
	var addClientForm = $("#addClientOrderForms").Validform({
		tiptype:1
	});
	var bool = addClientForm.check();
	if(bool==false){
		$("#saveClientOrdersId").popover("toggle");
		return;
	}
	
	var form = $("#addClientOrderForms").serialize();
	var data=form+"&clientQuotaId="+$("#clientQuota").val();
	//获取提交路径
	var url="/trade-wzj-web/tests/kfddAdd";
	var bol = postMethod(url,data,"POST");
	if(bol){
		alert("操作成功!");
	}else{
		alert("操作失败!");
	}
	$("#saveClientOrdersModal").modal("hide");
}